package cn.ekuma.epos.datalogic.define.dao;

import java.util.List;

import cn.ekuma.data.dao.ViewDAO;

import com.openbravo.bean.viewbean.ProductStoreDiaryView;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.QBFBuilder;
import com.openbravo.data.loader.SerializerWriteBasic;
import com.openbravo.data.loader.StaticSentence;

public class ProductStoreDiaryViewDAO extends ViewDAO<ProductStoreDiaryView>{

	static String LIST_SQL="SELECT S.DATENEW,S.REASON, S.LOCATION, S.PRODUCT, S.ATTRIBUTESETINSTANCE_ID,A.DESCRIPTION, S.UNITS, S.PRICE, S.LOTNO, S.VALIDITYDATE,S.BOMID,P.NAME  FROM STOCKDIARY S LEFT OUTER JOIN PRODUCTS P ON S.BOMID=P.ID LEFT OUTER JOIN ATTRIBUTESETINSTANCE A ON  S.ATTRIBUTESETINSTANCE_ID=A.ID  ";
	
	public ProductStoreDiaryViewDAO(I_Session s) {
		super(s);
	}

	@Override
	public Class getSuportClass() {
		return ProductStoreDiaryView.class;
	}

	@Override
	public ProductStoreDiaryView readValues(DataRead dr,
			ProductStoreDiaryView obj) throws BasicException {
	   if(obj==null)
		   obj=new ProductStoreDiaryView();
	   obj.setDate(dr.getTimestamp(1));
	   obj.setReason(dr.getString(2));
	   obj.setLocation(dr.getString(3));
	   obj.setProductID(dr.getString(4));
	   obj.setProductAttSetInstId(dr.getString(5));
	   obj.setProductAttrSetInstDec(dr.getString(6));
	   obj.setMultiply(dr.getDouble(7));
	   obj.setPrice(dr.getDouble(8));
	   obj.setLotNo(dr.getString(9));
	   obj.setValidityDate(dr.getTimestamp(10));
	   obj.setBomId(dr.getString(11));
	   obj.setBomName(dr.getString(12));
		return obj;
	}

    public List<ProductStoreDiaryView> list(Object filter) throws BasicException {
        return new StaticSentence(s, new QBFBuilder(
        		LIST_SQL+ "WHERE ?(QBF_FILTER)  ORDER BY S.DATENEW DESC ", new String[]{"S.DATENEW", "S.DATENEW", "S.LOCATION", "S.PRODUCT","S.LOTNO" }), new SerializerWriteBasic(new Datas[]{ Datas.OBJECT, Datas.TIMESTAMP, Datas.OBJECT, Datas.TIMESTAMP, Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.STRING}), this).list(filter);
    }

}
